package com.kuang.thread;

//多个线程同时操作同一个对象
//买火车票 有并发问题
public class TestThread04 implements Runnable{
    //票数
    private int ticketNums=10;

    public void run() {
        while (true){
            if (ticketNums<=0){
                break;
            }
            System.out.println(Thread.currentThread().getName()+"拿到了第"+ticketNums--+"张票");
        }
    }

    public static void main(String[] args) {
        TestThread04 testThread04 = new TestThread04();

        new Thread(testThread04,"小明").start();
        new Thread(testThread04,"老师").start();
        new Thread(testThread04,"黄牛").start();

    }
}
